package com.hand.db;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author FizzyElf
 * @version 1.0
 * @date 2022/9/1 23:00
 */
public class Conn {
    /**
     * oracle的驱动
     */
    static String driverClass="oracle.jdbc.driver.OracleDriver";
    static String url="jdbc:oracle:thin:@//123:15010/rbspitdb";
    static String user="123";
    static String password="123";

    /**
     * 获取数据库连接
     * @return 连接
     */
    public static Connection getconn() {
        Connection conn=null;
        try {
            //首先建立驱动
            Class.forName("oracle.jdbc.driver.OracleDriver");
            //驱动成功后进行连接
            conn= DriverManager.getConnection(url, user, password);

            System.out.println("连接成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }

    /**
     * 获取数据库连接
     * @return 连接
     */
    public static Connection getconn(String url, String user, String password) {
        Connection conn=null;
        try {
            //首先建立驱动
            Class.forName("oracle.jdbc.driver.OracleDriver");
            //驱动成功后进行连接
            conn= DriverManager.getConnection(url, user, password);

            System.out.println("连接成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }

}
